package com.example.android.moretextview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Dimension;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by android on 2017/9/5.
 */

public class MoreTextView extends LinearLayout implements View.OnClickListener {
    private TextView textContent;
    private ImageView updown;
    private int lines;//默认显示的行数
    private String text;
    private Paint paint;
    private int color;
    private float size;
    boolean isopen;


    public MoreTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.moretextview);
        lines = ta.getInteger(R.styleable.moretextview_textlines, 4);
        text = ta.getString(R.styleable.moretextview_textcontent);
        color = ta.getColor(R.styleable.moretextview_textcolor, Color.BLACK);
        size = ta.getDimension(R.styleable.moretextview_textsize, 16);
        setOrientation(LinearLayout.VERTICAL);
        textContent = new TextView(getContext());
        addView(textContent);
        updown = new ImageView(getContext());
        addView(updown);
        paint = new Paint();
        paint.setColor(color);
        paint.setTextSize(size);
        updown.setOnClickListener(this);
        updown.setImageResource(R.mipmap.ic_launcher_round);
        textContent.setText(text);
        textContent.post(new Runnable() {
            @Override
            public void run() {
                if (textContent.getLineCount() > 4) {
                    textContent.setLines(4);
                }
            }
        });
        ta.recycle();
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
    }

    @Override
    public void onClick(View view) {
        if (textContent.getLineCount() > 4) {
            if (isopen) {
                //开启一个打开的属性动画
            } else {
                //开启一个关闭的属性动画
            }
        }

    }
}
